/**
 * 二叉树
 */
function BinaryTree() {
    this.root = null;
}

BinaryTree.prototype.add = function(data) {
    if (this.root == null) {
        this.root = new Node(data)
    } else {
        this.compareAndInsert(this.root, data)
    }
}

BinaryTree.prototype.compareAndInsert = function(t, data) {
    if (t.data > data) {
        var left = t.left;
        if (left == null) {
            var n = new Node(data)
            t.left = n
            n.parent = t
        } else {
            this.compareAndInsert(left, data)
        }
    } else {
        var right = t.right;
        if (right == null) {
            var n = new Node(data)
            t.right = n
            n.parent = t
        } else {
            this.compareAndInsert(right, data)
        }
    }
}

function search(tree, x) {

}

var tree = new BinaryTree()

for (var i = 0; i < 10; i++) {
    var r = Math.random() * 100
    var data = Math.ceil(r)
    console.log(data)
    tree.add(data)
}

console.log(tree)